﻿<ResourceDictionary x:Class="Selen.Wpf.SystemStyles.AppTreeStyles"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Selen.Wpf.GenericAppTree;assembly=Selen.Wpf.GenericAppTree" mc:Ignorable="d">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Selen.Wpf.Core;component/Resources.xaml"/>
    </ResourceDictionary.MergedDictionaries> 
    <Style x:Key="MenuScrollBar" TargetType="ScrollBar">
        <Setter Property="MinWidth" Value="17" />
        <Setter Property="MinHeight" Value="17" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ScrollBar">
                    <Grid x:Name="Root">
                        <Grid.Resources>
                            <ControlTemplate x:Key="VerticalIncrementTemplate" TargetType="RepeatButton">
                                <Grid x:Name="Root" Margin="0,1,0,1">
                                    <Rectangle Name="rect" Fill="{StaticResource BackgroundNormal}"/>
                                    <Path Stretch="Uniform" Height="4" Width="8" Data="F1 M 531.107,321.943L 541.537,321.943L 536.322,328.042L 531.107,321.943 Z" Fill="{StaticResource Foreground}"/>
                                </Grid>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter TargetName="rect" Property="Fill" Value="{StaticResource BackgroundHighlighted}"/>
                                    </Trigger>
                                    <Trigger Property="IsPressed" Value="True">
                                        <Setter TargetName="rect" Property="Fill" Value="{StaticResource BackgroundSelected}"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                            <ControlTemplate x:Key="VerticalDecrementTemplate" TargetType="RepeatButton">
                                <Grid x:Name="Root" Margin="0,1,0,1">
                                    <Rectangle Name="rect" Fill="{StaticResource BackgroundNormal}"/>
                                    <Path Stretch="Uniform" Height="4" Width="8" Data="F1 M 541.537,173.589L 531.107,173.589L 536.322,167.49L 541.537,173.589 Z " Fill="{StaticResource Foreground}"/>
                                </Grid>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter TargetName="rect" Property="Fill" Value="{StaticResource BackgroundHighlighted}"/>
                                    </Trigger>
                                    <Trigger Property="IsPressed" Value="True">
                                        <Setter TargetName="rect" Property="Fill" Value="{StaticResource BackgroundSelected}"/>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Grid.Resources>
                        <Grid x:Name="VerticalRoot" HorizontalAlignment="Stretch">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <RepeatButton x:Name="VerticalSmallDecrease" Height="16" Margin="1" IsTabStop="False" Template="{StaticResource VerticalDecrementTemplate}" Grid.Row="0" Interval="50" Command="{x:Static ScrollBar.LineUpCommand}" />
                            <RepeatButton x:Name="VerticalSmallIncrease" Height="16" Margin="1" IsTabStop="False" Template="{StaticResource VerticalIncrementTemplate}" Grid.Row="2" Interval="50" Command="{x:Static ScrollBar.LineDownCommand}" />
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <LinearGradientBrush x:Key="BorderBrush" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#7FFFFFFF" Offset="0.05" />
        <GradientStop Color="#B2FFFFFF" Offset="0.07" />
        <GradientStop Color="#00FFFFFF" Offset="1" />
    </LinearGradientBrush>
    <LinearGradientBrush x:Key="FocusBorderBrush" EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FF6DBDD1" Offset="0" />
        <GradientStop Color="#FF64AEC0" Offset="1" />
    </LinearGradientBrush>
    <Style x:Key="FocusStyle" TargetType="{x:Type Border}">
        <Setter Property="CornerRadius" Value="2" />
        <Setter Property="Opacity" Value="0" />
        <Setter Property="BorderBrush" Value="{StaticResource FocusBorderBrush}" />
    </Style>
    <SolidColorBrush x:Key="DisabledBrush" Color="#B2FFFFFF" />
    <SolidColorBrush x:Key="ItemDisabledBrush" Color="#A5FFFFFF" />
    <Style x:Key="ItemDisabledStyle" TargetType="{x:Type Border}">
        <Setter Property="Background" Value="{StaticResource ItemDisabledBrush}" />
        <Setter Property="BorderBrush" Value="{StaticResource ItemDisabledBrush}" />
        <Setter Property="Opacity" Value="0" />
        <Setter Property="IsHitTestVisible" Value="False" />
        <Setter Property="CornerRadius" Value="2" />
    </Style>
    <ControlTemplate x:Key="C1TreeViewToggle" TargetType="{x:Type RadioButton}">
        <Grid Cursor="Arrow">
            <Grid.Resources>
                <Color x:Key="IconColor">#FF595959</Color>
                <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF" />
                <Color x:Key="FocusColor">#FF333333</Color>
            </Grid.Resources>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Path x:Name="ExpandIcon" Data="M17.25,0.5L17.25,17.25L0.5,17.25z" Height="6" HorizontalAlignment="Center" Margin="0,0,4,0" VerticalAlignment="Center" Width="6" Stretch="Fill" Stroke="#FF565656" StrokeThickness="0.5" Opacity="1" Visibility="Collapsed">
                <Path.Fill>
                    <LinearGradientBrush EndPoint="0.15,0.85" StartPoint="0.85,0.15">
                        <GradientStop Color="#FFF3F3F3" Offset="0" />
                        <GradientStop Color="#FFEBEBEB" Offset="0.5" />
                        <GradientStop Color="#FFDDDDDD" Offset="0.5" />
                        <GradientStop Color="#FFCDCDCD" Offset="1" />
                    </LinearGradientBrush>
                </Path.Fill>
                <Path.RenderTransform>
                    <TransformGroup>
                        <RotateTransform Angle="-45" CenterX="3" CenterY="3" />
                    </TransformGroup>
                </Path.RenderTransform>
            </Path>
            <Path x:Name="CollapseIcon" Data="M17.25,0.5L17.25,17.25L0.5,17.25z" Height="6" HorizontalAlignment="Center" VerticalAlignment="Center" Width="6" Opacity="0" Stretch="Fill" Stroke="#FF262626" StrokeThickness="0.5" Visibility="Collapsed">
                <Path.Fill>
                    <SolidColorBrush x:Name="IconColor" Color="{StaticResource IconColor}" />
                </Path.Fill>
            </Path>
            <Rectangle x:Name="ContentFocusVisual" Grid.Column="1" StrokeDashCap="Round" Margin="2" IsHitTestVisible="false" Visibility="Collapsed">
                <Rectangle.Stroke>
                    <SolidColorBrush Color="{StaticResource FocusColor}" />
                </Rectangle.Stroke>
            </Rectangle>
            <ContentPresenter x:Name="Content" Margin="6,5.5,4,4" IsHitTestVisible="true" Grid.Column="1" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Visibility="Collapsed" />
            <Rectangle x:Name="DisabledBox" Height="13" VerticalAlignment="Center" Width="13" Opacity="0" Fill="{StaticResource DisabledBrush}" Stroke="{StaticResource DisabledBrush}" StrokeThickness=".75" RadiusX="1" RadiusY="1" Visibility="Collapsed" />
            <Rectangle Grid.Column="1" Fill="#00FFFFFF" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="CollapseIcon" Property="Opacity" Value="1" />
                <Setter TargetName="ExpandIcon" Property="Opacity" Value="0" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <Style x:Key="BrowseTreeItemStyle" TargetType="{x:Type TreeViewItem}">
        <Setter Property="Margin" Value="1" />
        <Setter Property="Padding" Value="2" />
        <Setter Property="Background" Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeViewItem}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid MinHeight="20" x:Name="HeaderPanel" Grid.Row="0" Height="32" IsHitTestVisible="True">
                            <RadioButton GroupName="{Binding Group}" x:Name="ExpandButton" Template="{StaticResource C1TreeViewToggle}" IsThreeState="False" 
                                         Grid.ColumnSpan="2" ClickMode="Press" IsChecked="{Binding IsSelected, Mode=TwoWay}"/>
                            <Border Name="border" Grid.ColumnSpan="2" IsHitTestVisible="False" BorderThickness="1"
                                    Background="{StaticResource BackgroundNormal}" BorderBrush="{StaticResource BorderBrushNormal}"/>
                            <Grid Grid.ColumnSpan="2" Grid.Column="1" Margin="5 0 5 0">
                                <ContentPresenter x:Name="PART_Header" ContentSource="Header" ContentTemplate="{TemplateBinding HeaderTemplate}" 
                                                  TextElement.Foreground="{StaticResource Foreground}" IsHitTestVisible="False" HorizontalAlignment="Left" VerticalAlignment="Center" />
                            </Grid>
                        </Grid>
                        <ItemsPresenter Grid.Row="1" Visibility="Visible" x:Name="ChildrenPanel" Margin="10,2,0,2" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Background" TargetName="border" Value="{StaticResource BackgroundHighlighted}" />
                            <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource BorderBrushHighlighted}" />
                        </Trigger>
                        <Trigger Property="HasItems" Value="false">
                            <Setter Property="Visibility" TargetName="ChildrenPanel" Value="Collapsed" />
                        </Trigger>
                        <DataTrigger Binding="{Binding IsSelected}" Value="false">
                            <Setter Property="Visibility" TargetName="ChildrenPanel" Value="Collapsed" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsSelected}" Value="true">
                            <Setter Property="Background" TargetName="border" Value="{StaticResource BackgroundSelected}" />
                            <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource BorderBrushSelected}" />
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="MenuScrollViewer" TargetType="{x:Type ScrollViewer}">
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="VerticalScrollBarVisibility" Value="Visible"/>
        <Setter Property="Padding" Value="0" />
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2">
                        <Grid Background="{TemplateBinding Background}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid x:Name="measureGrid" />
                            <ScrollBar x:Name="PART_VerticalScrollBar" Visibility="Visible" IsTabStop="False" Orientation="Vertical" ViewportSize="{TemplateBinding ViewportHeight}" Maximum="{TemplateBinding ScrollableHeight}" Minimum="0" Value="{TemplateBinding VerticalOffset}" IsEnabled="True" Style="{StaticResource MenuScrollBar}" HorizontalAlignment="Stretch" Width="{Binding ActualWidth, ElementName=measureGrid}" />
                            <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" Cursor="{TemplateBinding Cursor}" ContentTemplate="{TemplateBinding ContentTemplate}" Margin="0,18" VerticalAlignment="Top" />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="AppTree" TargetType="{x:Type TreeView}">
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="ItemContainerStyle" Value="{StaticResource BrowseTreeItemStyle}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TreeView}">
                    <Grid x:Name="Root">
                        <Grid>
                            <ScrollViewer x:Name="scrollViewer" Style="{StaticResource MenuScrollViewer}" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled">
                                <ItemsPresenter />
                            </ScrollViewer>
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <HierarchicalDataTemplate DataType="{x:Type local:AppTreeContainer}" ItemsSource="{Binding Children}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="40"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Image Source="{Binding Icon}" Height="25" Width="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            <TextBlock Grid.Column="1" Text="{Binding Path=Header}" VerticalAlignment="Center"/>
        </Grid>
    </HierarchicalDataTemplate>
    <DataTemplate DataType="{x:Type local:AppTreeItem}">
        <Grid Margin="10,0,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="40"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Image Source="{Binding Icon}" Height="25" Width="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            <TextBlock Grid.Column="1" Text="{Binding Path=Header}" VerticalAlignment="Center"/>
        </Grid>
    </DataTemplate>
</ResourceDictionary>